package com.tepth.appmanageservice.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

import com.tepth.appmanageservice.ServiceMain;
import com.tepth.appmanageservice.enums.EServiceStr;
import com.tepth.appmanageservice.tools.ext.ExtService;

public class ServiceAppManage extends Service {
    private ServiceMain serviceMain;

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        return super.onUnbind(intent);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        serviceMain = new ServiceMain();
        serviceMain.Start();

        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        RestartService(this);
        super.onDestroy();
    }

    public static String RestartService(Context context) {
        boolean isWorked = ExtService.isServiceWorked(context, EServiceStr.serviceAi);
        if (!isWorked) {
            Intent service = new Intent(context, ServiceAppManage.class);
            context.startService(service);

            return "AiService 服务已启动…";
        } else {
            return "AiService 运行中…";
        }
    }
}